//生成时间:2023-03-30 16:32
var tuser={
    id:null,//編號
    Set_id:function(id){
        tuser.id=id.replace(/\'/g,"&apos;");
    },
    s_no:null,//工號
    Set_s_no:function(s_no){
        if(s_no.length<1 || s_no.length>30){
            return '工號的字数必须在1~30之间';
        }
        var reg=/^([A-Z]|[a-z]|\d)(\d{4,17}|(\d{4,17}[A-Z]\d{0,4}))|(^\d{18}$)|(^\d{17}(\d|X|x)$)$/;
        var patt=new RegExp(reg);
        if(!patt.test(s_no)){
            return '工號的格式不符合规定';
        }
        tuser.s_no=s_no.replace(/\'/g,"&apos;");
    },
    s_name:null,//姓名
    Set_s_name:function(s_name){
        if(s_name.length<1 || s_name.length>90){
            return '姓名的字数必须在1~90之间';
        }
        tuser.s_name=s_name.replace(/\'/g,"&apos;");
    },
    s_sex:null,//性別
    Set_s_sex:function(s_sex){
        if(s_sex.length<1 || s_sex.length>20){
            return '性別的字数必须在1~20之间';
        }
        var area=["男","女"];
        if(area.indexOf(s_sex)==-1){
            return '性別不在指定的范围内';
        }
        tuser.s_sex=s_sex.replace(/\'/g,"&apos;");
    },
    s_mail:null,//郵箱
    Set_s_mail:function(s_mail){
        if(s_mail.length<1 || s_mail.length>300){
            return '郵箱的字数必须在1~300之间';
        }
        var reg=/^([a-zA-Z]|[0-9])(\w|\-)+@(mail.foxconn.com)|(foxconn.com)$/;
        var patt=new RegExp(reg);
        if(!patt.test(s_mail)){
            return '郵箱的格式不符合规定';
        }
        tuser.s_mail=s_mail.replace(/\'/g,"&apos;");
    },
    s_tel:null,//分機
    Set_s_tel:function(s_tel){
        if(s_tel.length<1 || s_tel.length>60){
            return '分機的字数必须在1~60之间';
        }
        var reg=/(^\d{5,6}$)|(^\d{3}-\d{5,6}$)|(^\d{8,9}$)/;
        var patt=new RegExp(reg);
        if(!patt.test(s_tel)){
            return '分機的格式不符合规定';
        }
        tuser.s_tel=s_tel.replace(/\'/g,"&apos;");
    },
    s_birth:null,//生日
    Set_s_birth:function(s_birth){
        if(s_birth.length<1 || s_birth.length>20){
            return '生日的字数必须在1~20之间';
        }
        var reg=/(^\d{4}\/([1-9]|1[1-2])\/([1-9]|[1-2][0-9]|3[0-1])$)|(^\d{4}\-(0[1-9]|1[0-2])\-(0[1-9]|[1-2][0-9]|3[0-1])$)/;
        var patt=new RegExp(reg);
        if(!patt.test(s_birth)){
            return '生日的格式不符合规定';
        }
        tuser.s_birth=s_birth.replace(/\'/g,"&apos;");
    },
    UseForm: function (elem) {
        for (var key in tuser) {
            if (typeof tuser[key] == "function") {
                continue;//过滤方法
            }
            if (elem.querySelector("#" + key) ==null) {
                continue;//过滤不存在表单组件
            }
            var val = "";
            if(['INPUT','SELECT','TEXTAREA'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).value;
            };
            if(['IMG'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).src;
            };
            var res = tuser["Set_" + key](val);
            if (res) {
                return res;
            }
        }
        return null;
    },
    CreateFormdata: function () {
        var postData = new FormData();
        for (var key in tuser) {
            if (typeof tuser[key] == "function") {
                continue;//过滤方法
            }
            if (tuser[key] == null) {
                  continue;
            }
            postData.append(key, tuser[key]);
        }
        return postData;
    },
    CreateJson: function () {
        var json = {};
        for (var key in tuser) {
            if (typeof tuser[key] == "function") {
                continue;//过滤方法
            }
            if (tuser[key] == null) {
                  continue;
            }
            json[key] = tuser[key];
        }
        return json;
    }
}
